<template>
  <a-row :gutter="24">
    <a-col :md="24">
      <a-card :style="cardStyle" :bordered="false">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
          <!-- 搜索区域 -->
          <a-form layout="inline" @keyup.enter.native="searchQuery">
            <a-row :gutter="24">
              <a-col :md="6" :sm="24">
                <a-form-item label="搜索" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input placeholder="请输入车牌号或手机号查询" v-model="queryParam.keyword"></a-input>
                </a-form-item>
              </a-col>
              <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                <a-col :md="6" :sm="24">
                  <a-button type="primary" @click="searchQuery">查询</a-button>
                  <a-button style="margin-left: 8px" @click="searchReset">重置</a-button>
                </a-col>
              </span>
            </a-row>
          </a-form>
        </div>
        <!-- 操作按钮区域 -->
        <div class="table-operator" style="margin-top: 5px">
          <a-button v-if="btnEnableList.indexOf(1)>-1" @click="handleAdd" type="primary" icon="plus">新增</a-button>
          <a-button v-if="btnEnableList.indexOf(1)>-1" @click="batchDel" icon="delete">删除</a-button>
        </div>
        <!-- table区域-begin -->
        <div>
          <a-table
            ref="table"
            size="middle"
            bordered
            rowKey="id"
            :columns="columns"
            :dataSource="dataSource"
            :pagination="ipagination"
            :scroll="scroll"
            :loading="loading"
            :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
            @change="handleTableChange">
            <span slot="action" slot-scope="text, record">
              <a @click="handleEdit(record)">编辑</a>
              <a-divider v-if="btnEnableList.indexOf(1)>-1" type="vertical"/>
              <a-popconfirm v-if="btnEnableList.indexOf(1)>-1" title="确定删除吗?"
                            @confirm="() => handleDelete(record.id)">
                <a>删除</a>
              </a-popconfirm>
            </span>
            <template slot="customPic" slot-scope="text, record">
              <div>
                <img :src="item" v-for="item in getImgUrl(record.image)"
                     style="width:52px;height:52px;" class="item-img"
                     @click="showBigImage(item)"/>
              </div>
            </template>
            <!-- 状态渲染模板 -->
            <template slot="customRenderFlag" slot-scope="enabled">
              <a-tag v-if="enabled" color="green">启用</a-tag>
              <a-tag v-if="!enabled" color="orange">禁用</a-tag>
            </template>
          </a-table>
        </div>
        <!-- table区域-end -->
        <!-- 表单区域 -->
        <car-modal ref="modalForm" @ok="modalFormOk"></car-modal>
        <import-file-modal ref="modalImportForm" @ok="modalFormOk"></import-file-modal>
      </a-card>
    </a-col>
    <a-modal :visible="isModalVisible" @ok="isModalVisible =false" :footer="null" :width="800"
             @cancel="isModalVisible =false">
      <img :src="bigImageUrl" alt="大图" style="width: 750px;">
    </a-modal>
  </a-row>
</template>
<!-- b y 7 5 2 7  1 8 9 2 0 -->
<script>
import CarModal from './modules/CarModal'
import ImportFileModal from '@/components/tools/ImportFileModal'
import {JeecgListMixin} from '@/mixins/JeecgListMixin'
import JDate from '@/components/jeecg/JDate'
import Vue from 'vue'
import {pageCar} from "@api/api";
import {getFileAccessHttpUrl} from "@api/manage";

export default {
  name: "CarList",
  mixins: [JeecgListMixin],
  components: {
    CarModal,
    ImportFileModal,
    JDate
  },
  data() {
    return {
      isModalVisible: false,
      bigImageUrl: null,
      labelCol: {
        span: 5
      },
      wrapperCol: {
        span: 18,
        offset: 1
      },
      // 查询条件
      queryParam: {
        supplier: '',
        type: '供应商',
        telephone: '',
        phonenum: ''
      },
      ipagination: {
        pageSizeOptions: ['10', '20', '30', '100', '200']
      },
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {title: '车牌号', dataIndex: 'carNumber', width: 150, align: "left"},
        {title: '司机', dataIndex: 'driver', width: 70, align: "left"},
        {title: '手机号码', dataIndex: 'mobile', width: 100, align: "left"},
        {title: '图片', dataIndex: 'image', width: 100, align: "left", scopedSlots: {customRender: 'customPic'}},
        {
          title: '操作',
          dataIndex: 'action',
          width: 100,
          align: "center",
          scopedSlots: {customRender: 'action'},
        }
      ]
    }
  },
  computed: {},
  created() {
    this.searchReset()
  },
  methods: {
    loadData() {
      pageCar({
        page: this.ipagination.current,
        pageSize: this.ipagination.pageSize,
        keyword: this.queryParam.keyword
      }).then((res) => {
        this.dataSource = res.data.records
        this.ipagination.current = res.data.current
        this.ipagination.total = res.data.total
      })
    },
    searchReset() {
      this.queryParam = {}
      this.ipagination.current = 1;
      this.loadData();
    },
    getImgUrl(img) {
      if (img && img.split(',')) {
        return img.split(',')
      } else {
        return []
      }
    },
    showBigImage(url) {
      this.bigImageUrl = url
      this.isModalVisible = true
      console.log(url)
    },
    handleEdit: function (record) {
      this.$refs.modalForm.edit(record);
      this.$refs.modalForm.title = "编辑";
      this.$refs.modalForm.disableSubmit = false;
      if (this.btnEnableList.indexOf(1) === -1) {
        this.$refs.modalForm.isReadOnly = true
      }
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>